/*
 * GTKViews.cpp
 *
 *  Created on: 12/06/2014
 *      Author: javier
 */

#include "GTKViews.h"
#include "Properties.h"
#include "CampaignEditorWindow.h"
#include "LevelEditorWindow.h"
#include "EditorController.h"

GTKViews::GTKViews(int argc, char* argv[]) {
	Properties properties;
	this->controller = NULL;
	app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
	levelEditor = NULL;
	campaignEditor = NULL;
	Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file(
			properties.getProperty("ui"));

	builder->get_widget_derived("campaignWindow", campaignEditor);
	builder->get_widget_derived("levelWindow", levelEditor);

	campaignEditor->setLevelEditor(levelEditor);
	levelEditor->setCampaignWindow(campaignEditor);

//	levelEditor->hide();
//	campaignEditor->show_all();
}

void GTKViews::run() {
	app->run(*campaignEditor);
}

void GTKViews::init(EditorController* controller) {
	this->controller = controller;
	campaignEditor->setController(controller);
	levelEditor->setController(controller);
	if (campaignEditor) {
		campaignEditor->setCampania(controller->getCampania());
		campaignEditor->loadCampaignInfo();
	}
	if (levelEditor) {
		levelEditor->setCampania(controller->getCampania());
	}
}

GTKViews::~GTKViews() {
	// TODO Auto-generated destructor stub
}
